import logging
from typing import Optional

import PySide6.QtCore
import PySide6.QtWidgets
from PySide6.QtCore import QMetaType, Qt, Signal, QSettings
from PySide6.QtGui import QAction, QIcon
from PySide6.QtWidgets import (QGridLayout, QTreeWidget, QTreeWidgetItem,
                               QWidget)

from ...ToolWidgetBar import ToolWidgetBar
from .TreeWidgetTrace import TreeWidgetTrace
from ....PSData import *
from ..ActiveDataBuffer import ActiveDataBuffer


class Trace(QWidget, PSDataServer, ActiveDataBuffer):

    # signalAddTraceRow = Signal(QTreeWidgetItem)
    def __init__(
        self, 
        parent: Optional[PySide6.QtWidgets.QWidget] = None, 
        f: PySide6.QtCore.Qt.WindowFlags = Qt.Widget) -> None:
        ###############################################
        super().__init__(parent=parent, f=f)
        # id_ = QMetaType.Type('QTreeWidgetItem')
        self._log = logging.getLogger()
        self._gridLayout = QGridLayout(self)
        self._gridLayout.setObjectName('gridLayout')
        self._gridLayout.setContentsMargins(0,0,0,0)

        # 1 添加 ToolWidgetBar
        self._toolWidgetBar = ToolWidgetBar(self)
        self._gridLayout.addWidget(self._toolWidgetBar, 0, 0)
        # 2 添加 TreeWidgetTrace
        self._treeWidgetTrace = TreeWidgetTrace(self)
        self._gridLayout.addWidget(self._treeWidgetTrace, 1, 0)
        # 3 创建 Action
        self._toolWidgetBar.InsertToolButton(self._treeWidgetTrace.actionPasueContinue)

        # 设置信号槽
        # self.signalAddTraceRow.connect(self._treeWidgetTrace.AddRow)


